package org.game.manager;

import org.bean.AccountInfo;
import org.bean.NoticeDTO;
import org.game.cache.NoticeCache;
import org.game.cache.OnlinePlayerCache;
import org.game.db.cache.PlayerCache;
import org.game.module.noticebo.NoticeBO;
import org.game.msgBuilder.NoticeMsgBuilder;
import org.game.protobuf.s2c.S2CNoticeMsg;
import org.game.util.ProtoUnit;

import java.util.List;

/**
 * Created by fxf on 2018-1-9.
 */
public class NoticeManager {

    public static void broadcastMarqueeNotice(List<Integer> noitceIdList){
        noitceIdList.forEach(id->{
            NoticeDTO notice = NoticeCache.getNoticeById(id);
            if (notice == null){
                return;
            }
            S2CNoticeMsg.MarqueeNotice msg = NoticeMsgBuilder.getMarqueeNoticeMsg(notice);
            OnlinePlayerCache.getAll().forEach(player -> player.getPlayerProxy().sendMsg(NoticeBO.pushMarqueeNotice,msg));
        });

    }
    
    /** 通知在线玩家刷新公告 */
    public static void broadcastNotice(){
        OnlinePlayerCache.getAll().forEach(player -> {
            AccountInfo info = player.getPlayerProxy().getAccountInfo();
            int channel = info.getChannelId();
            int channelAppId = info.getChannelAppId();
            List<NoticeDTO> noticeList = NoticeCache.getBillboardNotice(channel, channelAppId);
            player.getPlayerProxy().sendMsg(NoticeBO.getBillboardNotice,NoticeMsgBuilder.getBillBoardNoticeListMsg(noticeList));
        });
    }
}
